<?php
/**
 * Created by PhpStorm OF Administrator.
 * User: YUYI
 * Date: 2018/7/26 0026
 * Time: 下午 5:13
 * Administrator
 */

namespace app\api\controller;


use app\common\model\AccountBook;
use app\common\model\BankList;
use app\common\model\UserEquipments;
use app\common\model\Users;
use app\common\service\DateService;
use app\common\service\PushService;
use app\common\util\ReturnMsgUtil;

class Warning
{
    use ReturnMsgUtil;
    public function __construct()
    {
        $sign = input('sign');
        if (!$sign){
            die($this->errorInfo('您无权访问此接口'));
        }
        if ($sign != md5('sign')){
            die($this->errorInfo('您无权访问此接口'));
        }
    }

    public function index()
    {
        $bls = BankList::all(['repaymentDate'=>date('d')]);
        foreach ($bls as $bl){
            $ab = new AccountBook();
            $amount = $ab->where(['bid'=>['=',$bl->id],'createTime'=>['between',[DateService::lastMonth($bl->statementDate),DateService::lastLastMonth($bl->statementDate)]]])->sum('amount');
            $ue = UserEquipments::get(['user_id'=>$bl->userId]);
            $res = PushService::pushToOneUser($ue->Getui_client_id,'今天是您的还款日！','今天'.$bl->name.$bl->card_number.'卡需要偿还￥'.$amount.'!');
        }
    }
}